home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr10 / inter35c.zip / INT2GUID.ZIP / INT2GUID.C < prev    next >
Text File  |  1993-04-04  |  22KB  |  721 lines

  1. /* INT2GUID.C
  2.  *
  3.  * from:
  4.  * INT2QH.C
  5.  *
  6.  * Author:   Kai Uwe Rommel
  7.  * Date:     Sun 07-Oct-1990
  8.  * Update:   Sat 20-Oct-1990
  9.  * Update:   Sun 11-Nov-1990  Ralf Brown
  10.  *
  11.  * Compiler: MS C 5.00 and newer / compact model, or TC 2.0 / compact model
  12.  * System:   PC/MS-DOS 3.20 and newer, OS/2 1.0 and newer
  13.  *
  14.  *
  15.  * INT2GUID.C is a GUIDE/MAKEHELP version of INT2QH.C. GUIDE and MAKEHELP
  16.  * are programs for pop-up help included the TurboPower Software package
  17.  * Turbo Professional.
  18.  *
  19.  * Transscriptor:    Bent Lynggaard
  20.  * Date:    1.00    Sun 24-Mar-1991
  21.  * Update:    1.01    Tue 02-Apr-1991    - test '!', ';' in line pos 1.
  22.  *                    - test disk full
  23.  *        1.02    Sun 14-Apr-1991    - smaller index pages
  24.  *                    - main index always leads to start of
  25.  *                      an INT #
  26.  *        1.03    Sun 12-May-1991    - configuration file.
  27.  *        1.04    Sat 18-May-1991 - conditional mask in *.cfg
  28.  *        1.05    Sun 29-Dec-1991 - fixed \n bug in configure()
  29.  *        1.06    Sun 09-May-1992 - adjusted for change in file format
  30.  *                    - "dividerline" info as headings
  31.  *                    - all registers can carry parameters
  32.  *        1.07    Sat 19-Dec-1992 - fixed bug (reading from closed file)
  33.  *                    - "dividerline" info as topics
  34.  *                    - "dividerline" char 9 function info
  35.  *                    - new subtopic criteria
  36.  *                    - program initialization in
  37.  *                        configuration file
  38.  *                    - splitting up long topics
  39.  *        1.08    Sun 04-Apr-1993 - topic # in "Missing divider line"
  40.  *                        to ease manual editing
  41.  *
  42.  * This program creates output to the standard output device. The output
  43.  * should be redirected to a file INTERRUP.TXT. The created file should
  44.  * be compiled by the TurboPower MAKEHELP program to a INTERRUP.HLP file,
  45.  * which can be interpreted by the TurboPower GUIDE TSR program:
  46.  *    INT2GUID > [ramdisk:]INTERRUP.TXT
  47.  *    MAKEHELP [ramdisk:INTERRUPT] INTERRUP[.HLP] /Q
  48.  *    GUIDE INTERRUP    (or enter GUIDE with a hot key, press F3,
  49.  *            enter INTERRUP)
  50.  *
  51.  * TurboPower Software supplies a program called POPHELP in their Object
  52.  * Professional package, which is a successor to GUIDE. INT2GUID has
  53.  * facilities for conditional interpretation of supplementary files, so
  54.  * these files can include code optimized for both GUIDE and POPHELP, and
  55.  * the parts compiled depends on a mask defined in the configuration file.
  56.  *
  57.  * The following is considered in creating the topic (and popup window)
  58.  * headers:
  59.  * The first word in the header is the interrupt number, so that GUIDE's
  60.  * search mechanism can find the entry if the hot key is pressed when
  61.  * the cursor is at an interrupt number.
  62.  * MAKEHELP restricts the (length of longest header + 1) times the number
  63.  * of topics to 64 kB. INTER191 had about 2200 topics, so the length of
  64.  * the headers should be limited to 25 characters. However, rather than
  65.  * truncating the INTERRUP.LST header lines to some nonsense, this
  66.  * program uses only the interrupt number as topic headings, plus the
  67.  * AH or AX values where applicable.
  68.  * (v. 1.06: "divider line" info (e.g. "214C" in "--------214C------...")
  69.  * is used for headings, thus allowing a more selective search by GUIDE's
  70.  * cursor-word search.)
  71.  * The main index references some subindeces. The subindeces use the
  72.  * MAKEHELP cross reference facility. MAKEHELP limits the number of cross
  73.  * references to 50 per topic, however, this program limits each subindex
  74.  * to 18 entries, so each "topic" can be shown on one single screen with
  75.  * height 20 lines. For each interrupt number, the entries are temporarily
  76.  * stored, and written to the current subindex page only if all entries
  77.  * for the interrupt number fit on the page.
  78.  *
  79.  * MAKEHELP's text wrapping mechanism is disabled, and as the active
  80.  * window is limited to 76 characters, some lines are missing one or two
  81.  * characters.
  82.  * The amount of text that can be displayed per topic is limited by
  83.  * GUIDE's setting of pages/topic (default = 20) and the screen height
  84.  * defined when GUIDE was initialized.
  85.  *
  86.  */
  87.  
  88. #define LABEL    "int2guid.c"
  89. #define VERSION  "1.07"
  90.  
  91. #include <stdio.h>
  92. #include <stdlib.h>
  93. #include <string.h>
  94. #include <ctype.h>
  95.  
  96. #define divider_line(s) (strncmp(s,"--------",8)==0)
  97. #define maxIndeces 18
  98.   /* max 50, 18 gives one page with height 20 (18 active lines) */
  99. #define mainIndex 200
  100.   /* 1-99 reserved for program, 100-199 reserved for user */
  101. #define false 0
  102. #define true 1
  103.  
  104. FILE *input, *output, *topics, *subtopics, *config;
  105.  
  106. char line1[128];
  107. char line2[128];
  108. char configline[128];
  109. char tempBuffer[50 * 128];
  110. char *tempPtr;
  111. char category[4] = "--";
  112. char nextHeader[16] = "??"; /* v. 1.07: 16 rather than 14 */
  113. char infilename[14] = "interrup.lst";
  114. #define infileExt 9
  115. int splitInfile = 0;
  116. int classification = 0;
  117. int WIDTH = 80;
  118.   /* WIDTH is the screen with for GUIDE/POPHELP. 80 is the best choice for
  119.      GUIDE, 78 is the best choice for POPHELP (which does not count the
  120.      frame as a part of the screen). The configuration file can change
  121.      this value. v. 1.07.
  122.   */
  123. long topicStart = 0; /* v. 1.07 */
  124. unsigned maxTopicLength = 32000; /* v. 1.07 */
  125.   /* texts longer than maxTopicLength are split into two or more topics.
  126.      The configuration file can change this value.
  127.   */
  128. char currentHeader[16]; /* v. 1.07 */
  129.  
  130. char configfile[14] = "int2guid.cfg";
  131. char configmarker[18] = "INT2GUIDE CONFIG";
  132.  
  133. char missingFile[] = "Missing include file.";
  134.  
  135. int sub = 0, indexed = 1;
  136. unsigned currentID = 1, activeID = 1, indeces = 0, indexNo = 0, buffered = 0,
  137.   subindeces, activeSub, mask;
  138. int headerlength; /* v. 1.07 */
  139. unsigned reservedID = mainIndex; /* v. 1.07 */
  140.   /* reservedID reserves some topic numbers for long texts that are split
  141.      into more than one topic. currentID must then be incremented via a
  142.      function call in order to skip the reserved topics.
  143.   */
  144.  
  145. void exitfunc(void)
  146. {
  147.   fcloseall();
  148.   unlink("topic.tmp");
  149.   unlink("subtopic.tmp");
  150. }
  151.  
  152. void errorexit(char *msg)
  153. /* writes msg to stderr and exits with error code 1 */
  154. {
  155.   fputs(msg, stderr);
  156.   exit(1);
  157. } /* errorexit */
  158.  
  159. void diskFull(int temporary)
  160. /* reports disk full and exits */
  161. {
  162.   char msg[80];
  163.   sprintf(msg,"\n\nDisk full, %s file\n", temporary ? "temporary" : "output");
  164.   errorexit(msg);
  165. } /* diskFull */
  166.  
  167.  
  168. int _fputs(char *line, FILE *stream)
  169. /* filters TABs to spaces, and inserts a leading space in lines starting
  170.    with the MAKEHELP command and comment characters '!' and ';'. "_fputs"
  171.    should be used when copying from unknown sources. Use "fputs" when
  172.    copying files with information specifically for this program.
  173. */
  174. {
  175.   char buffer[128];
  176.   int cnt = 0;
  177.  
  178.   if ( (*line=='!') || (*line==';') ) /* MAKEHELP command/comment? */
  179.     buffer[cnt++] = ' '; /* start with a space */
  180.  
  181.   while ( *line )
  182.   {
  183.     switch ( *line )
  184.     {
  185.       case '\t': do buffer[cnt++] = ' '; while ( cnt & 7 ); break;
  186.             /* MAKEHELP does not interpret tabs */
  187.       default  : buffer[cnt++] = *line;
  188.     }
  189.     line++;
  190.   }
  191.  
  192.   buffer[cnt] = 0;
  193.  
  194.   if ( (cnt = fputs(buffer, stream)) == EOF )
  195.     diskFull(stream != output);
  196.  
  197.   return cnt;
  198. }
  199.  
  200. char *_fgets(char *s, int n, FILE *stream)
  201. {
  202.   char *ptr;
  203.   ptr = fgets(s, n, stream);
  204.   if ( (ptr==NULL) && (stream==input) && splitInfile )
  205.   {
  206.     fclose(input);
  207.     infilename[infileExt]++;
  208.     input = fopen(infilename, "r");
  209.     if ( input != NULL )
  210.     {
  211.       fprintf(stderr, "%s\n", infilename);
  212.       ptr = fgets(s, n, input);
  213.     }
  214.   }
  215.   return ptr;
  216. } /* _fgets */
  217.  
  218. void Initialize(void)
  219. {
  220.   input     = fopen(infilename, "r");
  221.   if ( input == NULL )
  222.   {
  223.     infilename[infileExt] = 'a';
  224.     infilename[infileExt+1] = 0;
  225.     input = fopen(infilename, "r");
  226.     if ( input == NULL )
  227.     {
  228.       fputs("Cannot open input file (INTERRUP.LST or INTERRUP.A)\n", stderr);
  229.       exit(1);
  230.     }
  231.     splitInfile = 1;
  232.   }
  233.   fprintf(stderr, "%s\n", infilename);
  234.   output    = stdout;
  235.   topics    = fopen("topic.tmp", "w");
  236.   subtopics = fopen("subtopic.tmp", "w");
  237.  
  238.   tempPtr = tempBuffer;
  239.  
  240.   fprintf(output,
  241.     ";INTERRUPT help text for MAKEHELP/GUIDE.\n;\n!WIDTH %u\n;\n",WIDTH);
  242.     /* v. 1.07: WIDTH  rather than constant 80. WIDTH is initialized to 80
  243.        and can be changed in the configuration file.
  244.     */
  245.   fprintf(topics, "!TOPIC 1 Interrupt List\n!INDEX %u\n", mainIndex);
  246. }
  247.  
  248. int incrementID(void)
  249. /* v. 1.07: introduced in order to skip reserved IDs when incrementing currentID */
  250. {
  251.   ++currentID;
  252.   if (currentID == mainIndex)
  253.     currentID = reservedID;
  254.   return currentID;
  255. } /* incrementID */
  256.  
  257. void testTopic(void) /* limit xrefs/topic to maxIndeces */
  258. {
  259.   if ( indeces+buffered >= maxIndeces ) /* leave one entry for forw. ref */
  260.   {
  261.     incrementID();
  262.     fprintf(topics, "\004%u\005INT %s\005 (index continued)\n"
  263.       "!TOPIC %u INT %s (cont)\n!INDEX %u\n"
  264.       "(continued \004%u\005from\005)\n",
  265.       currentID, category, currentID, category, ++indexNo, activeID);
  266.     indeces = 1; /* the backwards ref */
  267.     activeID = currentID;
  268.   }
  269. } /* testTopic */
  270.  
  271. void copyBuffer(void)
  272. {
  273.   if ( buffered == 0 )
  274.     return;
  275.  
  276.   testTopic();
  277.   if ( fputs(tempBuffer, topics) == EOF )
  278.       diskFull(true);
  279.   indeces += buffered;
  280.   buffered = 0;
  281.   tempPtr = tempBuffer;
  282. } /* copyBuffer */
  283.  
  284. void Cleanup(void)
  285. {
  286.   copyBuffer();
  287.   fclose(topics);
  288.   fclose(subtopics);
  289.   fputs("Cleaning up\n", stderr);
  290.  
  291.   topics = fopen("topic.tmp", "r");
  292.   subtopics = fopen("subtopic.tmp", "r");
  293.  
  294.   while ( fgets(line1, sizeof(line1), topics) )
  295.     if ( fputs(line1, output) == EOF )
  296.       diskFull(false);
  297.  
  298.   while ( fgets(line1, sizeof(line1), subtopics) )
  299.     if ( fputs(line1, output) == EOF )
  300.       diskFull(false);
  301. } /* Cleanup */
  302.  
  303. void putAndCount(int putFunc(), char *line)
  304. /* split topic if maxTopicLength is exceeded. v. 1.07 */
  305. {
  306.   int ID, rID;
  307.   if ((ftell(output) - topicStart) > maxTopicLength)
  308.   {
  309.     ID = currentID;
  310.     rID = (reservedID > currentID) ? reservedID++ : ++currentID;
  311.     if (fprintf(output,"\004%u\005(text continues)\005\n"
  312.       "!TOPIC %u %s\n!NOINDEX\n"
  313.       "\004%u\005(text continued from)\005\n",
  314.       rID, rID, currentHeader, ID) == EOF)
  315.     diskFull(false);
  316.     topicStart = ftell(output);
  317.   }
  318.   if (putFunc(line, output) == EOF)
  319.     diskFull(false);
  320. } /* putAndCount */
  321.  
  322. int CopyFile(char *name, int commands)
  323. /* copies a file to the database, returns 0 for success or 1 for error */
  324.  
  325. /* If commands!=0, also interprets lines starting with "!! <number>" as
  326.    an update to variable "condition", and copies lines to the database
  327.    only if condition == 0 or (condition & mask) != 0
  328. */
  329. {
  330.   int condition = 0;
  331.   FILE *temp = fopen(name, "r");
  332.   char s[128];
  333.   fprintf(stderr, "%s\n", name);
  334.   if ( temp == NULL )
  335.   {
  336.     fprintf(stderr, "WARNING: Could not open %s\n", name);
  337.     fputs("Information was not available\n", output);
  338.     return 1;
  339.   }
  340.   else
  341.   {
  342.     while ( fgets(line2, sizeof(line2), temp) )
  343.       if ( !commands )
  344.     putAndCount(_fputs, line2);
  345.       else
  346.     /* does line start with "!! <number>" ? */
  347.     if ( sscanf(line2, "!!%i", &condition) != 1 )
  348.       /* yes: condition updated, sscanf returns 1 */
  349.       if ( (condition==0) || (condition & mask) )
  350.       {
  351.         if (sscanf(line2, "!%s", s) == 1)
  352.           if (strcmp(strupr(s), "TOPIC") == 0)
  353.             topicStart = ftell(output);
  354.         putAndCount(fputs, line2);
  355.       }
  356.     fputs("!NOWRAP\n", output); /* in case it was left in !WRAP state */
  357.     fclose(temp);
  358.     return 0;
  359.   }
  360. } /* CopyFile */
  361.  
  362. void testTemp(void)
  363. /* v. 1.06: allow no more than 50 entries in tempBuffer */
  364. /* v. 1.07: allow no more than 48 entries in tempBuffer */
  365. {
  366.   if (buffered >= 48)
  367.   {
  368.     copyBuffer();
  369.     fprintf(stderr,"INT %s has more than 48 subtopics and therefore more than one entry\n"
  370.       "in the main index (topic %u).\n", category, currentID);
  371.   }
  372. } /* testTemp */
  373.  
  374. void testSubtopic(char *marker)
  375. {
  376.   if ( ++subindeces >= maxIndeces )
  377.   {
  378.     testTemp();
  379.     sprintf(tempPtr, "\004%u\005%s\005  (list cont.)\n",
  380.       incrementID(), marker);
  381.     tempPtr += strlen(tempPtr);
  382.     buffered++;
  383.     fprintf(subtopics,
  384.       "\004%u\005%s\005  (list cont.)\n!TOPIC %u %s (list cont)\n!NOINDEX\n"
  385.       "(continued \004%u\005from\005)\n",
  386.       currentID, marker, currentID, category, activeSub);
  387.       activeSub = currentID;
  388.     subindeces = 2;
  389.   }
  390. } /* testSubtopic */
  391.  
  392.  
  393. void StartTopic(char *header, char *marker, char *desc)
  394. {
  395.   topicStart = ftell(output); /* v. 1.07 */
  396.   strncpy(currentHeader, header, sizeof(currentHeader));
  397.   currentHeader[sizeof(currentHeader)-1] = 0;
  398.   if (sub)
  399.   {
  400.     testSubtopic(marker);
  401.     if ( fprintf(subtopics, "\004%u\005%s\005  %s",
  402.       incrementID(), marker, desc) == EOF )
  403.     diskFull(true);
  404.     if (fprintf(output, "\004%u\005INT %s\005 (continued)\n",
  405.       currentID, category) == EOF)
  406.         diskFull(false);
  407.     /* insert a reference to this one in the former topic */
  408.   } /* if (sub) */
  409.   else
  410.   {
  411.     testTemp();
  412.     sprintf(tempPtr, "\004%u\005%s\005  %s", incrementID(), marker, desc);
  413.     tempPtr += strlen(tempPtr);
  414.     buffered++;
  415.   } /* else */
  416.  
  417.   fprintf(output, "!TOPIC %u %s\n", currentID, header);
  418.   if ( indexed )
  419.     indexNo++;
  420.   fprintf(output, indexed ? "!INDEX %u\n" : "!NOINDEX\n", indexNo);
  421. } /* StartTopic */
  422.  
  423. void StartList(void)
  424. /* v. 1.07: reorganized and edited */
  425. {
  426.   fprintf(subtopics, "!TOPIC %u %s (list)\n!NOINDEX\n", incrementID(), category);
  427.   if (fputs(tempBuffer, subtopics) == NULL)
  428.     diskFull(true); /* copy one entry in buffer to subtopics */
  429.   sub = 1;
  430.   subindeces = 1;
  431.   activeSub = currentID;
  432.   tempPtr = tempBuffer; /* reset buffer pointer */
  433.   buffered = 1; /* the entry we are going to use now */
  434.   sprintf(tempPtr, "\004%u\005%s\005  (list)\n", currentID, category);
  435.   tempPtr += strlen(tempPtr);
  436. } /* StartList */
  437.  
  438. /* void EndList(void) - not used */
  439.  
  440. /* char *NextID(void) - not used */
  441.  
  442. int RecognizedTopic(void)
  443. {
  444. /* v. 1.07: revised to use newheader info for marker string rather than
  445.    interpreting lines 1 and 2, and to use subtopics when there is more
  446.    than one entry rather than when there are entries with parameters.
  447. */
  448.   char *ptr, *pdesc, topic[4], marker[20];
  449.  
  450.   if (input == NULL)
  451.     return 0; /* v. 1.07: check input == NULL rather than read second line */
  452.  
  453.   if ( (pdesc = strchr(line1, '-')) == NULL )
  454.     pdesc = "(description not found)";
  455.  
  456.   if (headerlength==0) /* if info was missing in the dividerline */
  457.   { /* take INT # from line1[4]-[5] */
  458.     strncpy(nextHeader, &line1[4], 2);
  459.     nextHeader[2] = '\0';
  460.     fprintf(stderr,"Missing divider line info in topic %u:\n%s",
  461.       currentID, line1); /* 1.08: edited */
  462.   }
  463.   strncpy(topic, nextHeader, 2); /* interrupt number */
  464.   topic[2] = '\0';
  465.  
  466.   if ( strcmp(category, topic) )
  467.   {
  468.     sub = 0;
  469.     copyBuffer();
  470.     strcpy(category, topic);
  471.     fprintf(stderr, "%s\015", topic); /* show progress */
  472.   }
  473.   else
  474.   {
  475.     if (sub==0) /* v. 1.07 */
  476.       StartList();
  477.     /* v. 1.07: insert reference was moved to StartTopic */
  478.   }
  479.  
  480.   strcpy(marker, nextHeader); /* v. 1.07: use nextHeader for marker */
  481.   /* nextheader format: IIAHALXXNNNN_F (_F only if headerlength<0 */
  482.   /* marker format: II AHAL XXNNNN F */
  483.   if (headerlength < 0)
  484.   {
  485.     headerlength = abs(headerlength);
  486.     marker[headerlength-2] = ' '; /* '_' to space */
  487.   }
  488.  
  489.   if (headerlength > 2)
  490.   {
  491.     for (ptr = marker+headerlength+1; ptr >= &marker[2]; ptr--)
  492.       ptr[1] = *ptr;
  493.     /* memcpy(&marker[3], &marker[2], headerlength - 1);
  494.        did not work properly (compiler direction handling error)
  495.     */
  496.     marker[2] = ' ';
  497.     if (headerlength > 6+2)
  498.     {
  499.       for (ptr = marker+headerlength+2; ptr >= &marker[7]; ptr--)
  500.     ptr[1] = *ptr;
  501.       /* memcpy(&marker[8], &marker[7], headerlength - 5);
  502.         again. compiler error
  503.       */
  504.       marker[7] = ' ';
  505.       ptr = &marker[6];
  506.       while (*ptr == '_')
  507.     *ptr-- = ' '; /* spaces for AL or AX if unused */
  508.     } /* if (headerlength > 6+2) */
  509.   } /* if (headerlength > 2) *
  510.  
  511. /* v. 1.06: use global "nextHeader" rather than local "header" */
  512. /* v. 1.07: local "header" deleted */
  513.   StartTopic(nextHeader, marker, pdesc);
  514.  
  515.   _fputs(line1, output);
  516.  
  517.   return 1;
  518. } /* RecognizedTopic */
  519.  
  520. void CopyTopic(void)
  521. {
  522. /* v. 1.07: edited to split long texts into two or more topics */
  523.   char *ptr, *ptr2;
  524.  
  525.   for (;;)
  526.   {
  527.     if ( _fgets(line1, sizeof(line1), input) == NULL )
  528.       break;
  529.  
  530.     if ( !divider_line(line1) )
  531.       putAndCount(_fputs, line1);
  532.     else
  533.     {
  534.       if ( _fgets(line2, sizeof(line2), input) == NULL )
  535.     break;
  536.  
  537.       if ( strncmp(line2, "INT ", 4) )
  538.       {
  539.     putAndCount(_fputs, line1);
  540.     putAndCount(_fputs, line2);
  541.       }
  542.       else
  543.       {
  544.     /* v. 1.06: store divider line info as a header */
  545.     /* v. 1.07: edited */
  546.     strncpy(nextHeader, line1+10, 12);
  547.     for (ptr=nextHeader+11; *ptr=='-'; ptr--)
  548.       ;
  549.     if (ptr>&nextHeader[4])
  550.       for (ptr2=&nextHeader[2]; ptr2<ptr && ptr2<&nextHeader[6]; ptr2++)
  551.         if (*ptr2 == '-')
  552.           *ptr2 = '_';
  553.     headerlength = ptr - nextHeader + 1;
  554.     if (classification && line1[8]!='-')
  555.     {
  556.       *++ptr='_'; /* add char. 9 function classification */
  557.       *++ptr=line1[8];
  558.       headerlength = -headerlength-2;
  559.     }
  560.     *++ptr=0;
  561.     strcpy(line1, line2);
  562.     break;
  563.       } /* else */
  564.     } /* else */
  565.   } /* for (;;) */
  566. } /* CopyTopic */
  567.  
  568. void configError(void)
  569. {
  570.   errorexit("\nFormat error in configuration file.\n");
  571. } /* configError */
  572.  
  573. void readconfig(void)
  574. /* reads one line from file config to configline */
  575. {
  576.   if ( fgets(configline, sizeof(configline), config) == NULL )
  577.     configError();
  578. } /* readconfig */
  579.  
  580. void openconfig(void)
  581. /* opens configuration file and reads the initial part up to a line starting
  582.    with "=". This code defines how the initial lines are interpreted.
  583.    v. 1.07 defines:
  584.    configline[0] == '=': end of initial part
  585.    configline[0] == ';': comment
  586.    configline[0] == 'W': assign value to WIDTH
  587.    configline[0] == 'M': assign value to maxTopicLength
  588.    configline[0] == 'C': assign true to classification
  589.    The definitions are case sensitive.
  590. */
  591. {
  592.   int confv, confsubv;
  593.   char dummy[128];
  594.   config = fopen(configfile, "r");
  595.   if ( config == NULL )
  596.   {
  597.     fputs("\nWarning: No configuration file.\n", stderr);
  598.     return;
  599.   }
  600.   readconfig();
  601.   if (strncmp(configline, configmarker, strlen(configmarker)))
  602.     configError();
  603.   readconfig();
  604.   if (sscanf(configline, "%u%u", &confv, &confsubv) < 2)
  605.     configError();
  606.   if ((confv = ((confv << 8) + confsubv)) < 0x104)
  607.     errorexit ("\nThe configuration file is incompatible with this"
  608.     " version of INT2GUID");
  609.   if (confv < 0x107)
  610.     return;
  611.   while (!feof(config))
  612.   {
  613.     readconfig();
  614.     switch (configline[0])
  615.     {
  616.       case '=': return; /* done */
  617.       case ';': break; /* comment */
  618.       case 'W':
  619.       case 'M':
  620.     if ( sscanf(configline, "%s%u", &dummy,
  621.       configline[0]=='W' ? &WIDTH : &maxTopicLength) < 2 )
  622.       configError();
  623.     break;
  624.       case 'C': classification = true; break; /* include classification */
  625.       default: fprintf(stderr, "\nWARNING: Error in configuration file:\n%s",
  626.     configline);
  627.     } /* switch */
  628.   } /* while */
  629. } /* openconfig */
  630.  
  631. void copyline(char *str, int len)
  632. /* copies configline (after deleting the terminating '\n') to str
  633.     for max len characters. */
  634. {
  635.   configline[strlen(configline)-1] = 0; /* ignore '\n' */
  636.   strncpy(str, configline, len);
  637.   str[len] = 0; /* edited: v. 1.05 */
  638. } /* copyline */
  639.  
  640. void configure(void)
  641. /* parses configuration file */
  642. {
  643. #define maxHeader 14
  644. #define markerLen 12
  645.   int command, extraTopics, i;
  646.   char header[(maxHeader+2) & 0xFE], marker[(markerLen+2) & 0xFE],
  647.     desc[(76-markerLen) & 0xFE], filename[80];
  648.   /* v. 1.07: initial part moved to openconfig() */
  649.   while ( !feof(config) )
  650.   {
  651.     while ( (fgets(configline, sizeof(configline), config) != NULL)
  652.       && (configline[0] == ';') ) ;
  653.     if feof(config) break;
  654.     copyline(filename, 79);
  655.     readconfig();
  656.     copyline(header, maxHeader);
  657.     readconfig();
  658.     copyline(marker, markerLen);
  659.     i = strlen(marker);
  660.     while ( i<markerLen-1 ) /* pad with spaces if short */
  661.       marker[i++] = ' '; /* is already 0-terminated at markerLen */
  662.     readconfig();
  663.     copyline(desc, 76-markerLen-2);
  664.     i = strlen(desc); /* edited: v. 1.05 */
  665.     desc[i] = '\n';
  666.     desc[++i] = 0;
  667.     readconfig();
  668.     if ( sscanf(configline, "%u%u%i", &command, &extraTopics, &mask) < 3 )
  669.       configError();
  670.  
  671.     StartTopic(header, marker, desc);
  672.     CopyFile(filename, command);
  673.     currentID += extraTopics;
  674.   }
  675.   fclose(config);
  676. #undef maxHeader
  677. #undef markerLen
  678. } /* configure */
  679.  
  680. void main(void)
  681. {
  682.   fprintf(stderr, "\nINT2GUID %s - (c) Kai Uwe Rommel/Bent Lynggaard - %s\n",
  683.     VERSION, __DATE__);
  684.   atexit(exitfunc);
  685.  
  686.   openconfig();
  687.  
  688.   Initialize(); /* uses topic 1 */
  689.  
  690.   fputs("Including:\n",stderr);
  691.   StartTopic("Copyright etc.", "Copyright  ", "and references.\n");
  692.   if ( CopyFile("int2guid.ref", true) ) /* topic 2 */
  693.     errorexit(missingFile);
  694.  
  695.   StartTopic("INTERRUP.LST", "HEADER     ", "Overview of the Interrupt List\n");
  696.   fputs("(See also \4""4\5INTERRUP.1ST\5)\n", output); /* insert reference */
  697.   CopyTopic(); /* topic 3 */
  698.  
  699.   StartTopic("INTERRUP.1ST", "Mail etc.  ", "How to get/update INTERRUP.LST\n");
  700.   if ( CopyFile("interrup.1st", false) ) /* topic 4 */
  701.     errorexit(missingFile);
  702.  
  703.   StartTopic("GUIDE Program", "GUIDE      ", "Popup Reference Engine.\n");
  704.   if ( CopyFile("int2guid.gui", true) ) /* topic 5 */
  705.     errorexit(missingFile);
  706.  
  707.   configure();
  708.  
  709.   indexed = 0;
  710.   indexNo = mainIndex;
  711.  
  712.   while ( RecognizedTopic() )
  713.     CopyTopic();
  714.  
  715.   Cleanup();
  716.  
  717.   exit(0);
  718. }
  719.  
  720. /* End of INT2GUID.C */
  721.